﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using YunHan.BuShi123.BLL;
using YunHan.BuShi123.Model;
using System.Data.SqlClient;

public partial class admin_ad_list : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            btnAdd.OnClientClick = Window1.GetShowReference("/admin/ad/Edit.aspx?status=1", "新增链接");
            Bind();
        }
    }
    /// <summary>
    /// 弹出窗体
    /// </summary>
    /// <param name="ID"></param>
    /// <param name="name"></param>
    /// <returns></returns>
    protected string GetEditUrl(object ID, object name)
    {
        return Window1.GetShowReference("/admin/ad/Edit.aspx?status=2&MID=" + ID, "编辑 - " + name);
    }

    /// <summary>
    /// 查询
    /// </summary>
    /// <param name="semder"></param>
    /// <param name="e"></param>
    protected void btnSearch_Click(object semder, EventArgs e)
    {
        Grid1.PageIndex = 0;
        Bind();
    }

    /// <summary>
    /// 绑定数据
    /// </summary>
    private void Bind()
    {
        string Where = "";
        List<SqlParameter> Parms = new List<SqlParameter>();

        if (!string.IsNullOrEmpty(tbxcx1.Text.Trim()))
        {
            Where += " AND sort >= @sort1";
            Parms.Add(new SqlParameter("@sort1", tbxcx1.Text.Trim() ));
        }
        if (!string.IsNullOrEmpty(tbxcx2.Text.Trim()))
        {
            Where += " AND sort <= @sort2";
            Parms.Add(new SqlParameter("@sort2", tbxcx2.Text.Trim()));
        }

        if (Where.Length > 0)
        {
            Where = Where.Remove(0, 5);
        }



        int RecordCount = 0;
        List<Friendship_Model> Friendship = Friendship_BLL.GetModelListByPage(ref RecordCount, Where, "", "", Grid1.PageSize, Grid1.PageIndex + 1, Parms.ToArray());
        Grid1.DataSource = Friendship;
        Grid1.DataBind();
        Grid1.RecordCount = RecordCount;

    }

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="semder"></param>
    /// <param name="e"></param>
    protected void Grid1_RowCommand(object semder, FineUI.GridCommandEventArgs e)
    {
       
            //执行del语句
            int ID = Convert.ToInt32(Grid1.DataKeys[e.RowIndex][0]);


            int Result = Friendship_BLL.DeleteByKeyField(null, ID);
            if (Result > 0)
            {
                FineUI.Alert.Show("执行成功");
                Bind();
            }
            else
            {
                FineUI.Alert.Show("执行失败");
            }

    }


    /// <summary>
    /// 翻页
    /// </summary>
    /// <param name="semder"></param>
    /// <param name="e"></param>
    protected void Grid1_PageIndexChange(object semder, FineUI.GridPageEventArgs e)
    {
        Grid1.PageIndex = e.NewPageIndex;
        Bind();
    }
    
}